var ValidateUtil = {
    checkInputNull: function (fieldName, label) {
        var fieldValue = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage = "请输入" + label;
        if (fieldValue == undefined || fieldValue == null || fieldValue == '') {
            document.getElementById(fieldError).innerHTML = errMessage.fontcolor("red");
            return true;
        } else {
            document.getElementById(fieldError).innerHTML = "";
            return false;
        }
    },
    checkSelectNull: function (fieldName, label) {
        var fieldValue = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage = "请选择" + label;
        if (fieldValue == undefined || fieldValue == null || fieldValue == '') {
            document.getElementById(fieldError).innerHTML = errMessage.fontcolor("red");
            return true;
        } else {
            document.getElementById(fieldError).innerHTML = "";
            return false;
        }
    },
    checkEmail: function (fieldName) {
        var email = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请输入邮箱";
        var errMessage2 = "邮箱格式不正确";
        var reg = /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}\.[a-zA-Z0-9]{1,5}/;
        if (email == undefined || email == null || email == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(email)) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkPhone: function (fieldName) {
        var phone = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请输入手机号";
        var errMessage2 = "手机格式不正确";
        var reg = /^1(3|4|5|7|8)\d{9}$/;
        if (phone == undefined || phone == null || phone == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(phone)) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkIdCard: function (fieldName) {
        var idCard = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请输入身份证号";
        var errMessage2 = "身份证号格式不正确";
        var reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
        if (idCard == undefined || idCard == null || idCard == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(idCard)) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkPwd: function (fieldName) {
        var pwd = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请输入密码";
        var errMessage2 = "密码的长度为 3-16，包含任意的字母、数字，不可以使用其他符号";
        var reg = /^([a-zA-Z0-9]){3,16}$/i;
        if (pwd == undefined || pwd == null || pwd == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(pwd)) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkAgainPwd: function (fieldName, fieldName2) {
        var pwd = document.getElementById(fieldName).value;
        var newpwd = document.getElementById(fieldName2).value;
        var fieldError = fieldName + "Error";
        var fieldError2 = fieldName2 + "Error"
        var errMessage1 = "请输入确认密码";
        var errMessage2 = "密码的长度为 3-16，包含任意的字母、数字，不可以使用其他符号";
        var errMessage3 = "密码与确认密码不一致";
        var reg = /^([a-zA-Z0-9]){3,16}$/i;
        if (newpwd == undefined || newpwd == null || newpwd == "") {
            document.getElementById(fieldError2).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(newpwd)) {
            document.getElementById(fieldError2).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        if (pwd != newpwd) {
            document.getElementById(fieldError).innerHTML = errMessage3.fontcolor("red");
            document.getElementById(fieldError2).innerHTML = errMessage3.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        document.getElementById(fieldError2).innerHTML = "";
        return false;
    },
    checkType: function (fieldName, fieldName2, fieldName3) {
        var userType = document.getElementById(fieldName).value;
        var officeId = document.getElementById(fieldName2).value;
        var fieldError = fieldName + "Error";
        var fieldError3 = fieldName3 + "Error"
        var errMessage1 = "请选择用户类型";
        var errMessage2 = "请选择所属部门";
        if (userType == undefined || userType == null || userType == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        } else {
            document.getElementById(fieldError).innerHTML = "";
            if (userType == "2" || userType == "3") {
                if (officeId == '') {
                    document.getElementById(fieldError3).innerHTML = errMessage2.fontcolor("red");
                    return true;
                } else {
                    document.getElementById(fieldError3).innerHTML = "";
                }
            }
        }
        return false;
    },
    checkUpdatePwd: function (fieldName, fieldName2) {
        var newPwd = document.getElementById(fieldName).value;
        var oldPwd = document.getElementById(fieldName2).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请输入新密码";
        var errMessage2 = "密码的长度为 3-16，包含任意的字母、数字，不可以使用其他符号";
        var errMessage3 = "新密码不能与原密码相同";
        var reg = /^([a-zA-Z0-9]){3,16}$/i;
        if (newPwd == undefined || newPwd == null || newPwd == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (!reg.test(newPwd)) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        if (newPwd == oldPwd) {
            document.getElementById(fieldError).innerHTML = errMessage3.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkApplyStartDate: function (fieldName) {
        var applyStartDate = document.getElementById(fieldName).value;
        var fieldError = fieldName + "Error";
        var errMessage1 = "请选择使用开始时间";
        var errMessage2 = "使用开始时间要大于当前时间";
        var starTime = applyStartDate.replace("/-/g", "/");//时间转换
        var dateStart = new Date(starTime);
        var dateNow = new Date();
        if (applyStartDate == undefined || applyStartDate == null || applyStartDate == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (dateStart < dateNow) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    },
    checkApplyEndDate: function (fieldName, fieldName2) {
        var applyStartDate = document.getElementById(fieldName).value;
        var applyEndtDate = document.getElementById(fieldName2).value;
        var fieldError = fieldName2 + "Error";
        var errMessage1 = "请选择使用结束时间";
        var errMessage2 = "使用结束时间要大于使用开始时间";
        var starTime = applyStartDate.replace("/-/g", "/");//时间转换
        var eneTime = applyEndtDate.replace("/-/g", "/");//时间转换
        var dateStart = new Date(starTime);
        var dateEnd = new Date(eneTime);
        if (applyEndtDate == undefined || applyEndtDate == null || applyEndtDate == "") {
            document.getElementById(fieldError).innerHTML = errMessage1.fontcolor("red");
            return true;
        }
        if (dateStart>dateEnd) {
            document.getElementById(fieldError).innerHTML = errMessage2.fontcolor("red");
            return true;
        }
        document.getElementById(fieldError).innerHTML = "";
        return false;
    }
};
